<template>
  <screen-cell :title="'设备完好率统计'">
    <div class="container">
      <div class="header fy-flex fy-flex__center">
          平均设备完好率
        <div>
          99.6%
        </div>
      </div>
      <div class="content">
        <div class="cell" v-for="(item, index) in list" :key="index">
          <div class="progress fy-flex fy-flex__center" ref="progressStyle">
            <div class="circle-progress_bg" :style="{'width': `${progressDiameter}px`,'height': `${progressDiameter}px`}"></div>
            <div class="circle-progress_wrapper" :style="{'width': `${progressDiameter}px`,'height': `${progressDiameter}px`}">
              <div class="wrapper">
                <div class="circle-progress left-circle" ref="leftCircle" :style="{'transform': `rotate(${getRotate(item.num)[0]}deg)`,'-webkit-transform': `rotate(${getRotate(item.num)[0]}deg)`}"></div>
              </div>
              <div class="wrapper right-wrapper">
                <div class="circle-progress right-circle" ref="rightCircle" :style="{'transform': `rotate(${getRotate(item.num)[1]}deg)`,'-webkit-transform': `rotate(${getRotate(item.num)[1]}deg)`}"></div>
              </div>
            </div>
            <div class="progress-data fy-flex fy-flex__center" :style="{'width': `${progressDiameter}px`,'height': `${progressDiameter}px`}">
              <p>{{item.num}}%</p>
            </div>
          </div>
          <p class="title">{{item.title}}</p>
        </div>
      </div>
    </div>
  </screen-cell>
</template>

<script>
import ScreenCell from "@/components/common/ScreenCell.vue";
import ScreenTitle from "@/components/common/ScreenTitle.vue";
export default {
  // 全局感知
  name: "",

  // 模板依赖
  components: {
    ScreenCell,
    ScreenTitle
  },
  filters: {},

  // 接口
  props: {},

  // 本地状态
  data() {
    return {
      list: [
        {
          title: "火灾报警系统",
          num: 92
        },
        {
          title: "喷淋",
          num: 97
        },
        {
          title: "消防栓",
          num: 95
        },
        {
          title: "水箱水位",
          num: 98
        },
        {
          title: "电气火灾报警",
          num: 91
        },
        {
          title: "可燃气体监测",
          num: 100
        },
        {
          title: "独立烟感探测器",
          num: 92
        },
        {
          title: "充电桩",
          num: 90
        }
      ],
      progressDiameter: 0
    };
  },
  computed: {},
  // 事件
  watch: {},
  beforeCreate() {},
  created() {},
  beforeMount() {},
  mounted() {
    this.initWrapperStyle();
  },
  beforeUpdate() {},
  updated() {},
  beforeDestroy() {},
  destroyed() {},
  // 非响应式的属性
  methods: {
    initWrapperStyle() {
      this.$nextTick(() => {
        let progressStyWidth = this.$refs.progressStyle[0].clientWidth;
        let progressStyHeight = this.$refs.progressStyle[0].clientHeight;
        progressStyWidth > progressStyHeight
          ? (this.progressDiameter = progressStyHeight)
          : (this.progressDiameter = progressStyWidth);
        this.progressDiameter -= this.progressDiameter % 10;
      });
    },
    getRotate(num) {
      let num0, num1;
      if (num > 50) {
        num0 = 45;
        num1 = 45 + (180 * (100 - num)) / 50;
      } else {
        num0 = 45 + (180 * (50 - num)) / 50;
        num1 = 45 + 180;
      }
      return [num0, num1];
    }
  }
};
</script>

<style lang="scss" scoped>
.container {
  position: relative;
  width: 100%;
  height: 36vh;
  .header {
    position: relative;
    margin-top: 5%;
    width: 100%;
    height: 7.2vh;
    color: white;
    font-size: 2.5rem;
    div {
      margin: auto 8%;
      padding: 0.2rem 2rem;
      border: 0.2rem solid #7ecef4;
      border-radius: 2rem;
      color: #fffe8d;
    }
  }
  .content {
    position: relative;
    width: 100%;
    height: 28.8vh;
    .cell {
      position: relative;
      float: left;
      margin-top: 3%;
      margin-left: 4%;
      width: 20%;
      height: 11.52vh;
      .progress {
        position: relative;
        width: 100%;
        height: 9.216vh;
        .circle-progress_bg {
          position: absolute;
          border-radius: 50%;
          border: 1rem solid #f5ce68;
          box-sizing: border-box;
        }
        .progress-data {
          position: absolute;
          p {
            color: white;
            font-size: 2.2rem;
            font-weight: 900;
          }
        }
        .circle-progress_wrapper {
          position: absolute;
          transform: rotate(90deg);
          -webkit-transform: rotate(90deg);
          .wrapper {
            position: relative;
            width: 50%;
            height: 100%;
            overflow: hidden;
            float: left;
          }
          .right-wrapper {
            transform: rotate(180deg);
            -webkit-transform: rotate(180deg);
          }
          .left-circle {
            border: 1rem solid #f1823f;
            border-top-color: transparent !important;
            border-right-color: transparent !important;
            border-radius: 50%;
          }
          .right-circle {
            margin-right: 0;
            border: 1rem solid #f1823f;
            border-top-color: transparent !important;
            border-right-color: transparent !important;
            border-radius: 50%;
          }
        }
        .circle-progress {
          transition: all 2s;
          position: relative;
          width: 200%;
          height: 100%;
          border-radius: 50%;
          box-sizing: border-box;
        }
      }
      .title {
        position: relative;
        color: white;
        line-height: 2rem;
      }
    }
  }
}
</style>
